package com.raspberryCar.model;

import com.pi4j.gpio.extension.pca.PCA9685Pin;

public class Camera extends ServoMotor{
	//定义舵机转动的角度
	private static final int[] anglesBelow = {800,850,900,950,1000,1050,1100,1150,1200,1250,1300,1350,1400};
	private static final int[] anglesAbove = {1150,1200,1250,1300,1350,1400,1450,1500,1550,1600,1650};
	
	private int positionBelow = 6;
	private int positionAbove = 6;
	private static Camera camera;
	private Camera() {
		// Define outputs in use for this example
		
		//设置云台初始位置
		gpioProvider.setPwm(PCA9685Pin.PWM_00, 1400);
	    gpioProvider.setPwm(PCA9685Pin.PWM_01, 1100);
	}
	public static Camera getInstance(){
//		if (camera == null) {
//			camera = new Camera();
//		}
		return camera;
	}
	public void left(){
		if (positionBelow+1 <= 13) {
			positionBelow++;
		}
		gpioProvider.setPwm(PCA9685Pin.PWM_01, anglesBelow[positionBelow]);
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	public void right(){
		if (positionBelow-1 >0) {
			positionBelow--;
		}
		gpioProvider.setPwm(PCA9685Pin.PWM_01, anglesBelow[positionBelow]);
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	public void up(){
		if (positionAbove-1 >0) {
			positionAbove--;
		}
		gpioProvider.setPwm(PCA9685Pin.PWM_00, anglesAbove[positionAbove]);
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	public void down(){
		if (positionAbove+1 <=11) {
			positionAbove++;
		}
		gpioProvider.setPwm(PCA9685Pin.PWM_00, anglesAbove[positionAbove]);
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		Camera camera = getInstance();
		camera.right();
	}
}
